import axios from "axios"

axios.interceptors.request.use(config => {
    const passUrl = ['api/login', 'api/register']
    if (passUrl.includes(config.url)) return config

    console.log('axiosconfig>>>>>>>>>>>>>>>',config);
    const tk = localStorage.getItem('@TOKEN')
    if(tk) {
        config.headers.Authorization = 'Bearer ' + tk
    } else {
        delete config.headers.Authorization
    }
    return config
})
axios.interceptors.response.use(response => {
    console.log(444444444444,response);
    const { msg, status } = response
    if(status === 1 && msg === 'ERROR TOKEN') {
        window.location.href = "/login"; 
    }
    return response
})
export default axios

